package com.da.lon.wang.xlg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.MSearchType;
import com.da.lon.wang.xlg.bean.ResultSearchBean.ResultSearchListBean.SearchResultOther;
import com.da.lon.wang.xlg.bean.ResultSearchBean.ResultSearchListBean.SearchResultOther.SearchResultOtherItems;
import com.da.lon.wang.xlg.util.ViewHolder;

import java.util.List;

public class Classify1Adapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<MSearchType> searchResultOthers;
    private Context context;

    private String otherNameString;
    private int clickPosition;

    public Classify1Adapter(List<MSearchType> list, Context context, String otherName, int clickPosition) {
        // TODO Auto-generated constructor stub

        inflater = LayoutInflater.from(context);

        this.context = context;
        this.clickPosition = clickPosition;

        if (otherName == null) {
            otherNameString = null;
        } else {

            this.otherNameString = otherName;
        }
        this.searchResultOthers = list;

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return searchResultOthers != null ? searchResultOthers.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return searchResultOthers.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        SearchResultOther searchResultOther = searchResultOthers.get(position).getOther();
        SearchResultOtherItems item = searchResultOthers.get(position).getItem();
        convertView = inflater.inflate(R.layout.ouka_classify1_titem, null);

        TextView nameTextView = ViewHolder.get(convertView, R.id.ouka_classify1_itname);
        TextView itemTextView = ViewHolder.get(convertView, R.id.ouka_classify1_ititem);

        if (searchResultOther != null) {
            nameTextView.setText(searchResultOther.getName());
        }
        if (item == null) {
            itemTextView.setText("全部");
        } else {
            /*
             * if (position == clickPosition) {
             * itemTextView.setText(otherNameString); }
             */
            itemTextView.setText(item.getId());
        }

        return convertView;
    }

}
